package cn.hfatec.shms.web.yk.ykDbb.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.yk.ykDbb.model.YkDbb;
import cn.hfatec.shms.web.yk.ykDbb.dao.YkDbbDao;
import cn.hfatec.shms.web.yk.ykDbb.model.YkDbbParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("YkDbbService")
public class YkDbbService {

    public static final String BEAN_ID = "YkDbbService";

    //注入Dao层
    @Resource(name = "YkDbbDao")
    private YkDbbDao ykDbbDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param ykDbbParams
     * @param page
     *
     */
    @Transactional
    public Table queryYkDbbTable(YkDbbParams ykDbbParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", ykDbbParams);
        return baseDao.queryTableByPage("queryYkDbb", params, page);
    }

    /**
     *
     * 插入数据
     * @param ykDbb
     *
     */
    @Transactional
    public void saveYkDbb(YkDbb ykDbb) {
        if(ykDbb.getId() != null) {
            YkDbb result = getYkDbb(ykDbb.getId());
            if(result != null) {
                ykDbbDao.update(ykDbb);
            } else {
                ykDbbDao.insert(ykDbb);
            }
        } else {
            ykDbbDao.insert(ykDbb);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteYkDbb(Integer id) {

        ykDbbDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param ykDbbList
     *
     */
    @Transactional
    public void deleteYkDbbBatch(List<String> ykDbbList) {
        for(String id : ykDbbList) {
            deleteYkDbb(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public YkDbb getYkDbb(Integer id) {

        return ykDbbDao.getYkDbbById(id);
    }
}